import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:panda/base/Constant.dart';
import 'package:panda/base/application.dart';
import 'package:panda/login/Welcome.dart';
import 'package:panda/set/FillAuthCode.dart';
import 'package:panda/util/AppSaveInfoUtil.dart';

import 'ArticleDetail.dart';

class VIPTestPage extends StatefulWidget {
  VIPTestPage({Key key}) : super(key: key);

  @override
  _VIPTestPageState createState() => _VIPTestPageState();
}

class _VIPTestPageState extends State<VIPTestPage> {
  String group_name = "", userName = "", avatar, code = "";
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    group_name = APPLIC.userInfoMap['user_msg']['group_name'];
    userName = APPLIC.userInfoMap['user_detail']['nickname'] == null
        ? APPLIC.userInfoMap['user_msg']['phone']
        : APPLIC.userInfoMap['user_detail']['nickname'];
    avatar = APPLIC.userInfoMap['user_detail']['avatar'];
    code = APPLIC.userInfoMap['user_msg']['auth_code'];
  }

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text(
          "店长权益",
          style: TextStyle(
              fontSize: ScreenUtil.getInstance().setSp(BIG_FONT_SIZE),
              color: Colors.black),
        ),
        elevation: 0.2,
        backgroundColor: Colors.white,
        brightness: Brightness.light,
        centerTitle: true,
        iconTheme: new IconThemeData(color: Colors.black),
      ),
      body: SingleChildScrollView(
        child: Container(
          color: white,
          width: MediaQuery.of(context).size.width,
          alignment: Alignment.topCenter,
          height: MediaQuery.of(context).size.height + 69.313,
          child: Column(
            children: <Widget>[
              Container(
                height: DP_15,
              ),
              Row(
                crossAxisAlignment: CrossAxisAlignment.center,
                mainAxisAlignment: MainAxisAlignment.center,
                children: <Widget>[
                  Container(
                    width: DP_15,
                  ),
                  GestureDetector(
                    behavior: HitTestBehavior.opaque,
                    child: ClipOval(
                      child: avatar == null
                          ? Image.asset(
                              "images/app_icon.png",
                              fit: BoxFit.cover,
                              width: ScreenUtil.getInstance().setWidth(DP_120),
                              height: ScreenUtil.getInstance().setWidth(DP_120),
                            )
                          : CachedNetworkImage(
                imageUrl:
                              avatar,
                              fit: BoxFit.cover,
                              width: ScreenUtil.getInstance().setWidth(DP_120),
                              height: ScreenUtil.getInstance().setWidth(DP_120),
                            ),
                    ),
                    onTap: () {
                      // Navigator.of(context).push(
                      //     new MaterialPageRoute(builder: (context) {
                      //   return new SystemPage();
                      // }));
                    },
                  ),
                  Container(
                    width: DP_15,
                  ),
                  Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: <Widget>[
                      Row(children: <Widget>[
                        Text(userName,
                            style: TextStyle(
                                fontSize: ScreenUtil.getInstance()
                                    .setSp(NORMAL_FONT_SIZE),
                                color: Colors.black)),
                        Container(width: 8),
                        GestureDetector(
                          behavior: HitTestBehavior.opaque,
                          onTap: () {
                            // Navigator.of(context).push(
                            //     new MaterialPageRoute(
                            //         builder: (context) {
                            //   return new VipCenterPage(
                            //     level: 1,
                            //   );
                            // }));
                          },
                          child: Container(
                            decoration: BoxDecoration(
                                borderRadius: BorderRadius.circular(2),
                                border: Border.all(color: black, width: 1)),
                            padding: EdgeInsets.fromLTRB(
                                ScreenUtil.getInstance().setHeight(DP_8),
                                0,
                                ScreenUtil.getInstance().setHeight(DP_8),
                                0),
                            margin: EdgeInsets.fromLTRB(0, 0,
                                ScreenUtil.getInstance().setHeight(DP_10), 0),
                            child: Text(
                              group_name,
                              style: TextStyle(
                                  fontSize: ScreenUtil.getInstance()
                                      .setSp(SMALL_FONT_SIZE - 3),
                                  color: black),
                            ),
                          ),
                        ),
                        Container(width: 8),
                      ]),
                      Container(
                        height: 5,
                      ),
                      GestureDetector(
                        child: Row(
                          children: <Widget>[
                            Text('邀请码',
                                style: TextStyle(
                                    fontSize: ScreenUtil.getInstance()
                                        .setSp(NORMAL_FONT_SIZE - 2),
                                    color: Colors.black54)),
                            Container(width: 5),
                            Text(
                              '$code',
                              style: TextStyle(
                                  fontSize: ScreenUtil.getInstance()
                                      .setSp(NORMAL_FONT_SIZE),
                                  color: mainColor),
                            ),
                            // Icon(Icons.content_copy,
                            //     size: 16, color: Colors.black45)
                          ],
                        ),
                        onTap: () {
                          // ClipboardData data =
                          //     new ClipboardData(text: code);
                          // Clipboard.setData(data);
                          // Fluttertoast.showToast(msg: "复制成功");
                        },
                        behavior: HitTestBehavior.opaque,
                      )
                    ],
                  ),
                  Expanded(
                    child: Center(
                      child: GestureDetector(
                        child: Container(
                            alignment: Alignment.center,
                            height: 28,
                            width: 80,
                            decoration: new BoxDecoration(
                                color: Color(0xFFE5373B),
                                borderRadius: BorderRadius.circular(4.0)),
                            padding: EdgeInsets.fromLTRB(5.0, 0.0, 5.0, 0.0),
                            child: Text("退  出",
                                style: TextStyle(
                                  fontSize: 14,
                                  color: Colors.white,
                                ))),
                        onTap: () {
                          saveString(TOKEN, null);
                          Navigator.of(context).pop();
                          Navigator.of(context)
                              .push(new MaterialPageRoute(builder: (context) {
                            return WelComePage();
                          }));
                        },
                        behavior: HitTestBehavior.opaque,
                      ),
                    ),
                  ),
                  // GestureDetector(
                  //   behavior: HitTestBehavior.opaque,
                  //   child: Container(
                  //     padding: EdgeInsets.fromLTRB(
                  //         ScreenUtil.getInstance().setHeight(20),
                  //         ScreenUtil.getInstance().setHeight(10),
                  //         ScreenUtil.getInstance().setHeight(20),
                  //         ScreenUtil.getInstance().setHeight(10)),
                  //     decoration: BoxDecoration(
                  //       color: mainColor,
                  //       borderRadius: BorderRadius.only(
                  //           topLeft: Radius.circular(30),
                  //           bottomLeft: Radius.circular(30)),
                  //     ),
                  //     child: Row(
                  //       crossAxisAlignment:
                  //           CrossAxisAlignment.center,
                  //       children: <Widget>[
                  //         Image.asset(
                  //           "images/icon_invitation.png",
                  //           scale: 1.3,
                  //         ),
                  //         Container(
                  //           width: 5,
                  //         ),
                  //         Text(
                  //           '邀请好友',
                  //           style: TextStyle(
                  //               fontSize: ScreenUtil.getInstance()
                  //                   .setSp(SMALL_FONT_SIZE),
                  //               color: white),
                  //         )
                  //       ],
                  //     ),
                  //   ),
                  //   onTap: () {
                  //     Navigator.of(context).push(
                  //         new MaterialPageRoute(builder: (context) {
                  //       return new InviteFriendPage();
                  //     }));
                  //   },
                  // )
                ],
              ),
              Container(
                child: Material(
                  child: Stack(
                    children: <Widget>[
                      Image.asset(
                        "images/test1.png",
                        fit: BoxFit.fitWidth,
                      ),
                      Positioned(
                        child: GestureDetector(
                          child: Row(
                            children: <Widget>[
                              Text(
                                '确定“成为店长”则视为同意',
                                style: TextStyle(
                                    color: black,
                                    fontSize:
                                        ScreenUtil.getInstance().setSp(25)),
                              ),
                              Text(
                                '《熊猫新零售经销商协议》',
                                style: TextStyle(
                                    color: mainColor,
                                    fontSize:
                                        ScreenUtil.getInstance().setSp(28)),
                              ),
                            ],
                          ),
                          onTap: () {
                            Navigator.of(context)
                                .push(MaterialPageRoute(builder: (context) {
                              return new ArticleDetailPage(
                                article_id: "51",
                              );
                            }));
                          },
                        ),
                        bottom: 80,
                        left: ScreenUtil.getInstance().setHeight(30),
                      ),
                      Positioned(
                        child: GestureDetector(
                          child: Image.asset(
                            "images/test2.png",
                            width: ScreenUtil.getInstance().setHeight(DP_320),
                          ),
                          onTap: () {
                            Navigator.of(context)
                                .push(MaterialPageRoute(builder: (context) {
                              return new FillAuthCodePage();
                            }));
                          },
                        ),
                        bottom: 20,
                        left: (MediaQuery.of(context).size.width -
                                ScreenUtil.getInstance().setHeight(DP_320)) /
                            2,
                      )
                    ],
                  ),
                  elevation: 2,
                  borderRadius: BorderRadius.circular(10),
                ),
                margin: EdgeInsets.all(15),
              )
            ],
          ),
        ),
      ),
    );
  }
}
